package com.cyzy.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.cyzy.dto.AdoptListDto;
import com.cyzy.dto.Result;
import com.cyzy.pojo.Activity;
import com.cyzy.service.ActivityService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * 认养接口
 */
@RestController
@RequestMapping("/activity")
public class ActivityController {
    
    @Autowired
    private ActivityService activityService;
    
    /**
     * 获取认养列表
     * @return 认养列表
     */
    @GetMapping("/list")
    public Result getList(Activity activity) {
        List<Activity> activityList = activityService.getList(activity);
        return Result.ok().data("activityList", activityList);
    }
    //分页查询
    @GetMapping("/page")
    public Result getUserPage(
            @RequestParam(defaultValue = "1",name="current") Integer current,
            @RequestParam(defaultValue = "3",name="size")Integer size) {

        // 创建分页对象
        Page<Activity> page = new Page<>(current, size);
//        Activity activity = new Activity();
//        activity.setActivityTitle(name);
        // 执行分页查询（无需写 SQL，MyBatis-Plus 自动处理）
        IPage<Activity> activityPage = activityService.selectPage(page, null); // 第二个参数为查询条件（可为 null）

        return Result.ok().data("activityList",activityPage);
    }
} 